package com.example.run.teacherhelper.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.run.teacherhelper.R;
import com.example.run.teacherhelper.module.MyClass;

import java.util.List;

/**
 * Created by run on 2015/10/16.
 */
public class ClassesAdapter extends ArrayAdapter<MyClass> {
    private Context context;
    private List<MyClass> myClassList=null;
    private int resourceId;
    public ClassesAdapter(Context context, int textViewResourceId, List<MyClass> objects) {
        super(context, textViewResourceId, objects);
        this.context=context;
        this.myClassList=objects;
        this.resourceId=textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyClass myClass=getItem(position);
        ViewHolder viewHolder;
        View view;
        if(convertView==null){
            view= LayoutInflater.from(context).inflate(resourceId,null);
            convertView=view;
            viewHolder=new ViewHolder();
            viewHolder.className=(TextView)convertView.findViewById(R.id.class_name);
            viewHolder.classTime=(TextView)convertView.findViewById(R.id.class_time);
            viewHolder.studentNum=(TextView)convertView.findViewById(R.id.students_numbers);
            view.setTag(viewHolder);
        }else {
            view=convertView;
            viewHolder= (ViewHolder) view.getTag();
        }

        viewHolder.className.setText(myClass.getClassName());
        viewHolder.studentNum.setText(myClass.getClassWork());
        viewHolder.classTime.setText(myClass.getClassTime());

        return view;
    }
    class ViewHolder{
        TextView className;
        TextView studentNum;
        TextView classTime;
    }
}
